package com.srd.phone.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shengrongdai.srd.R;
import com.srd.phone.bean.NoticeInfo;
import com.srd.phone.utils.views.ViewHolder;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class NoticeListAdapter extends BaseAdapter {

    private Context mContext;
    private List<NoticeInfo> list = new ArrayList<>();

    public NoticeListAdapter(Context context) {
        mContext = context;
    }

    public void setData(List<NoticeInfo> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        NoticeInfo info = list.get(position);
        ViewHolder viewHolder = ViewHolder.get(mContext, convertView, parent, R.layout.activity_notice_list_item, position);
        TextView tv_title = viewHolder.getView(R.id.tv_title);
        TextView tv_time = viewHolder.getView(R.id.tv_time);
        TextView tv_subtitle = viewHolder.getView(R.id.tv_subtitle);
        TextView tv_detail = viewHolder.getView(R.id.tv_detail);
        tv_title.setText(info.title);
        tv_subtitle.setText(info.subtitle);
        tv_time.setText(parser(info.ctime_Str));
        return viewHolder.getConvertView();
    }

    SimpleDateFormat formatDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    private String parser(String value) {
        try {
            Date mDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(value);
            return new SimpleDateFormat("yyyy-MM-dd").format(mDate);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}
